<%--
  Created by IntelliJ IDEA.
  User: xykdsg
  Date: 2020/12/10
  Time: 23:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
        <script src="${pageContext.request.contextPath}/js/jquery-2.1.0.min.js"></script>
        <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
        <script src="${pageContext.request.contextPath}/js/jquery-3.5.1.js"></script>
        <title>Title</title>
</head>
<body>

<form action="${pageContext.request.contextPath}/empsave" method="post">
        姓名：<input type="text" id="emp_name" name="emp_name" placeholder="请输入姓名"><br/>
        职务：<select id="dept_id" name="dept_id">
                <option value="1" selected>客户经理</option>
                <option value="2">销售经理</option>
        </select><br/>
        入职时间：<input type="text" id="join_date" name="join_date" placeholder="请输入入职时间"><br/>
        电话：<input type="text" id="telephone" name="telephone" placeholder="请输入电话"><br/>

        <input type="submit" value="提交" />
</form>
<hr/>
<form>
        部门名：<input type="text" id="dept_name" name="dept_name" value="市场部"><br/>
        部门主管：<input type="text" id="major_name" name="major_name" value="拉勾招聘"><br/>
        联系电话：<input type="text" id="tele" name="tele" value="400-400-4008"><br/>
        邮箱：<input type="text" id="email" name="email" value="lagou@163.com">

</form>

</body>

<script>
        $("#dept_id").change(function(){
                var deptId=$("#dept_id").val();
                alert(deptId);

                let url = '${pageContext.request.contextPath}/deptfind';

                $.ajax({
                        type: 'POST',
                        url: url,
                        data : {'id':deptId},
                        dataType :'json',
                        success: function (dept) {
                                var deptName = ${dept.dept_name};
                                var majorName = ${dept.major_name};
                                var tele = ${dept.telephone};
                                var email = ${dept.email};
                                $("#dept_name").val(deptName);
                                $("#major_name").val(majorName);
                                $("#tele").val(tele);
                                $("#email").val(email);
                        },
                        error:function (dept) {
                                var deptName = ${dept.dept_name};
                                var majorName = ${dept.major_name};
                                var tele = ${dept.telephone};
                                var email = ${dept.email};
                                $("#dept_name").val(deptName);
                                $("#major_name").val(majorName);
                                $("#tele").val(tele);
                                $("#email").val(email);
                        }
                })

        })

</script>
</html>
